function IR = sumar(W,mag)
 [F C] = size(mag);
 IR=zeros(F,C);
 flag1=zeros(F,C);
 flag2=zeros(F,C);
 
 Om = F/2;                  % coordenadas del centro de la imagen
 On = C/2;
 sx = F/2;                  % factores de escala
 sy = C/2;
 
 M=64;
 N=360;
  
 R=0.3;
 a=2^(1/M);
 rmin=(a^(-M/2))*R;
 rmax=(a^(M/2))*R;
 suma=0;
for xi = 1:F
  for yi = 1:C
    %x = (xi - Om)/sx;
    %y = ((-1)*yi + On)/sy;
     
    x = (xi - Om)/sx;
    y = (yi - On)/sy;
     
    r= sqrt(x^2 + y^2);
     
    if (r >=rmin) && (r <=rmax)
        
        theta = atan2(y,x);
        
        l1 =abs(floor((log2(r)-log2(R))/log2(a))+M/2);
       
        %l1 =abs(floor((log(r/R)/(log(a)))+M/2)); 
        l2 =abs(floor((N*theta)/pi));
          
        if(l1>=0 && l1<M) && (l2>=0 && l2<N)
          if(flag1(l1+1,l2+1)==0 && flag2(xi+1,yi+1)==0) 
            suma=suma+(W(l1+1,l2+1)*mag(xi+1,yi+1));
            flag1(l1+1,l2+1)=1;
            flag2(xi+1,yi+1)=1;
          end  
        end
     end 
  end
end
IR=suma;
end